#import "RNSegmentedControl.h"
#import "RNSegmentedCell.h"

@implementation RNSegmentedControl

-(void)performClickOnSegment:(NSInteger)segment {
    [(RNSegmentedCell *)[self cell] performClickOnSegment:segment];
}

-(BOOL)performKeyEquivalent:(NSEvent *)theEvent {
    NSString *characters = [theEvent charactersIgnoringModifiers];
    NSUInteger modifiers = [theEvent modifierFlags];
    RNSegmentedCell *segCell = (RNSegmentedCell *)[self cell];
    for (NSInteger segment = 0; segment < [segCell segmentCount]; segment++) {
        if ([characters isEqualToString:[segCell keyEquivalentForSegment:segment]] && modifiers & [segCell keyEquivalentModifierMaskForSegment:segment]) {
            [self performClickOnSegment:segment];
            return YES;
        }
    }
    return NO;
}

-(NSString *)keyEquivalentForSegment:(NSUInteger)segment {
    return [(RNSegmentedCell *)[self cell] keyEquivalentForSegment:segment];
}

-(NSUInteger)keyEquivalentModifierMaskForSegment:(NSUInteger)segment {
    return [(RNSegmentedCell *)[self cell] keyEquivalentModifierMaskForSegment:segment];
}

-(void)setKeyEquivalent:(NSString *)keyEquivalent forSegment:(NSUInteger)segment {
    [(RNSegmentedCell *)[self cell] setKeyEquivalent:keyEquivalent forSegment:segment];
}

-(void)setKeyEquivalentModifierMask:(NSUInteger)modifierMask forSegment:(NSUInteger)segment {
    [(RNSegmentedCell *)[self cell] setKeyEquivalentModifierMask:modifierMask forSegment:segment];
}

@end
